package world;

public class ChunkCoord2D {
	public final int indexX;
	public final int indexY;
	public final long ID;

	public ChunkCoord2D(int xIndex, int zIndex) {
		this.indexX = xIndex;
		this.indexY = zIndex;
		this.ID = getID(xIndex, zIndex);
	}

	/**
	 * converts a chunk coordinate pair to an integer (suitable for hashing)
	 */
	public static long getID(int par0, int par1) {
		return (long) par0 & 4294967295L | ((long) par1 & 4294967295L) << 32;
	}

	public int hashCode() {
		long i = this.ID;
		int j = (int) i;
		int k = (int) (i >> 32);
		return j ^ k;
	}

	public boolean equals(Object obj) {
		ChunkCoord2D o = (ChunkCoord2D) obj;
		return o.ID == this.ID;
	}

	public int getCenterXPos() {
		return (this.indexX << 4) + 8;
	}

	public int getCenterZPos() {
		return (this.indexY << 4) + 8;
	}

	public ChunkPosition getChunkPosition(int indexZ) {
		return new ChunkPosition(this.getCenterXPos(), indexZ, this.getCenterZPos());
	}

	public String toString() {
		return "[" + this.indexX + ", " + this.indexY + "]";
	}
}
